<style>
    .form-copy {
        margin-right: 5px;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px 7px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        border: 1px solid #ccc;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .select2 {
        margin-right: 5px
    }
</style>
{{-- 行选操作 start --}}
<input type="checkbox" class="grid-select-all" style="margin-right: 10px;"/>
<div class="btn-group">
    <a class="btn btn-sm btn-default">  {{ trans('admin.action') }}</a>
    <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#" class="grid-batch-1">生成发货单</a></li>
    </ul>
</div>
{{-- 行选操作 end --}}
<div class="btn-group" style="margin-right: 10px">
    <form action="{{ $action }}" pjax-container method="get">
        <input type="text" class="form-copy" name="order_no" value="{{ $filtersBlade['order_no'] }}" placeholder="订单号">
        <input type="text" class="form-copy" name="sku" value="{{ $filtersBlade['sku'] }}" placeholder="SKU信息">
        {{--<select id="status" name="status">
            {{ $filtersBlade['status'] }}
        </select>--}}
        <select id="plat_id" name="plat_id">
            {{ $filtersBlade['plat_id'] }}
        </select>
        <input style="width: 110px;" type="text" id="start_date" name="start_date" value="{{ $filtersBlade['start_date'] }}" class="form-copy" placeholder="下单开始日期">
        <input style="width: 110px;" type="text" id="end_date" name="end_date" value="{{ $filtersBlade['end_date'] }}" class="form-copy" placeholder="下单截止日期">
        <button class="btn btn-sm btn-info submit"><i class="fa fa-search"></i>&nbsp;&nbsp;{{ trans('admin.search') }}</button>
        <a style="margin-left: 10px;" href="{{ $action }}" class="btn btn-sm btn-default"><i class="fa fa-undo"></i>&nbsp;&nbsp;{{ trans('admin.reset') }}</a>
    </form>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('#status').select2({placeholder: '申请状态', allowClear: true, width: '150px'});
        $('#plat_id').select2({placeholder: '订单平台', allowClear: true, width: '150px'});
        $('#start_date').datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","maxDate":moment()});
        $('#end_date').datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","maxDate":moment()});

        //生成发货单
        $('.grid-batch-1').on('click', function() {

            let idArr = $.admin.grid.selected();

            if(idArr.length == 0){
                swal('请选择单据', '', 'error');
                return false;
            }

            let selectRows = [];
            $("input[type=radio]:checked").each(function() {

                let _this = $(this);
                let id = _this.data('id');
                let order_no = _this.data('order-no');
                let order_detail_id =_this.data('order-detail-id');
                let psku_id =_this.data('psku-id');
                let delivery_type = _this.data('delivery-type');
                let account_id = _this.data('account-id');
                let seller_sku = _this.data('seller-sku');
                let warehouse_id = _this.data('warehouse-id');
                let apply_num = $('#this_apply_num_' + id).val();
                let apply_remarks = $('#this_apply_remarks_' + id).val();

                let data = {
                    order_no: order_no,
                    order_detail_id: order_detail_id,
                    psku_id: psku_id,
                    delivery_type: delivery_type,
                    account_id : account_id,
                    seller_sku : seller_sku,
                    warehouse_id : warehouse_id,
                    apply_num : apply_num,
                    apply_remarks : apply_remarks,
                };

                selectRows.push(data);
            });

            if (selectRows.length == 0) {
                swal('请选择发货方式', '', 'error');
                return false;
            }

            $.ajax({
                method: 'post',
                url: '/xqc/customer-delivery/delivery-demand-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action: 'doCreateDelivery',
                    param: selectRows,
                },
                success: function (data) {
                    if (data.status) {
                        toastr.success(data.message);
                        $.pjax.reload('#pjax-container');
                    }else {
                        toastr.error(data.message);
                    }
                },
                error: function () {
                    swal(data.message, '', 'error');
                }
            });
        });

    });
</script>
